//
//  HKListAdapter.h
//  KSBridgeDesign
//
//  Created by huzhaoke on 2021/4/17.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "HKListSectionModel.h"

NS_ASSUME_NONNULL_BEGIN
@class HKListAdapter;
//  加载更多默认触发距离
extern CGFloat const kKSAdatperLoadMoreDefaultOffset;

@protocol HKAdapterLoadMoreDelegate <NSObject>

- (CGFloat)adapterLoadMoreOffset:(HKListAdapter *)adapter;
- (void)adapterOnLoadMore:(HKListAdapter *)adapter;
@optional
- (void)triggerLoadMoreIfNeeded:(HKListAdapter *)adapter;

@end

@interface HKListAdapter : NSObject

@property (nonatomic, weak, readonly) UIScrollView *scrollView;
//加载更多的代理
@property (nonatomic, weak) id<HKAdapterLoadMoreDelegate> loadMoreDelegate;

@property (nonatomic, weak) id<UIScrollViewDelegate> scrollViewDelegate;

@property (nonatomic, readwrite) NSMutableArray<HKListSectionModel *> *sectionModels;
//  Count
@property (nonatomic, assign, readonly) NSUInteger sectionCount;
@property (nonatomic, assign, readonly) BOOL isEmpty;
- (NSUInteger)cellModelsCountAtSection:(NSUInteger)section;

@property (nonatomic, assign) BOOL isLoading;

- (instancetype)initWithView:(__kindof UIScrollView *)view;

- (NSUInteger)indexOfSectionModel:(HKListSectionModel *)sectionModel;
- (nullable HKListSectionModel *)sectionModelAtSection:(NSUInteger)section;
- (nullable HKListCellModel *)cellModelAtIndexPath:(NSIndexPath *)indexPath;

- (HKListSectionModel *)sectionModelInSection:(NSUInteger)section;
- (NSIndexPath *)indexPathOfCellModel:(HKListCellModel *)cellModel;
- (NSUInteger)cellCountInSection:(NSUInteger)section;

- (void)clear;
- (void)addSectionModel:(HKListSectionModel *)sectionModel;
- (void)addSectionModels:(NSArray<HKListSectionModel *> *)sectionModels;
- (void)insertSectionModel:(HKListSectionModel *)sectionModel atIndex:(NSUInteger)index;
- (void)insertSectionModels:(NSArray<HKListSectionModel *> *)sectionModels atIndex:(NSUInteger)index;
- (void)removeSectionModel:(HKListSectionModel *)sectionModel;
- (void)removeSectionModels:(NSArray<HKListSectionModel *> *)sectionModels;
- (void)removeSectionModelAtIndex:(NSUInteger)index;

- (NSArray<HKListSectionModel *> *)subSectionModelsFromIndex:(NSUInteger)fromIndex;
- (NSArray<HKListSectionModel *> *)subSectionModelsToIndex:(NSUInteger)toIndex;
- (NSArray<HKListSectionModel *> *)subSectionModelsFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex;

- (nullable HKListCellModel *)cellModelForCell:(__kindof UIView *)cell;
//  Animation updates; Subclasses must override this method
- (void)performBatchUpdates:(void (NS_NOESCAPE ^)(__kindof HKListAdapter *adapter))updates
                   animated:(BOOL)animated
                 completion:(void (^ _Nullable)(BOOL finished))completion;

@end

NS_ASSUME_NONNULL_END
